/**
 * 
 */
package net.oauth.transport.http.util;

import net.oauth.transport.http.HttpParameters;

/**
 * @author Buhake Sindi
 * @since 08 February 2012
 *
 */
public class HttpParameterUtil {

	private HttpParameterUtil() {
	}
	
	public static HttpParameters parseQueryString(String queryString) {
		if (queryString == null) {
			return null;
		}
		
		HttpParameters parameters = new HttpParameters();
		String[] queryParameters = queryString.split("&");
		for (String parameter : queryParameters) {
			String[] kvs = parameter.split("=", 2);
			String key = kvs[0];
			String value = kvs[1];
			
			if (parameters.getParameter(key) == null) {
				parameters.setParameter(key, value);
			} else {
				parameters.getParameter(key).addValue(value);
			}
		}
		
		return parameters;
	}
}
